import { delay, takeEvery, put } from 'redux-saga/effects'

import { ADD_TODO, ADD_TODO_ASYNC } from '../actions/todo'
// const delay = (ms) => new Promise(resolve => setTimeout(resolve, ms))

function* todoAsync() {
    yield delay(2000)
    yield put({
        type: ADD_TODO,
        payload: {
            id: +new Date(),
            title: 12,
            isComplete: false
        }
    })
}

function* watchIncrementAsync() {
    yield takeEvery(ADD_TODO_ASYNC, todoAsync)
}

const todoSagas = [watchIncrementAsync()]

export default todoSagas
